home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
scheme.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-07-12
|
20KB
|
516 lines
;;; scheme.el --- Scheme mode, and its idiosyncratic commands.
;; Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
;; Author: Bill Rozas <jinz@prep.ai.mit.edu>
;; Keywords: languages, lisp
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Adapted from Lisp mode by Bill Rozas, jinx@prep.
;; Initially a query replace of Lisp mode, except for the indentation
;; of special forms. Probably the code should be merged at some point
;; so that there is sharing between both libraries.
;;; Code:
(defvar scheme-mode-syntax-table nil "")
(if (not scheme-mode-syntax-table)
(let ((i 0))
(setq scheme-mode-syntax-table (make-syntax-table))
(set-syntax-table scheme-mode-syntax-table)
;; Default is atom-constituent.
(while (< i 256)
(modify-syntax-entry i "_ ")
(setq i (1+ i)))
;; Word components.
(setq i ?0)
(while (<= i ?9)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
(setq i ?A)
(while (<= i ?Z)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
(setq i ?a)
(while (<= i ?z)
(modify-syntax-entry i "w ")
(setq i (1+ i)))
;; Whitespace
(modify-syntax-entry ?\t " ")
(modify-syntax-entry ?\n "> ")
(modify-syntax-entry ?\f " ")
(modify-syntax-entry ?\r " ")
(modify-syntax-entry ? " ")
;; These characters are delimiters but otherwise undefined.
;; Brackets and braces balance for editing convenience.
(modify-syntax-entry ?[ "(] ")
(modify-syntax-entry ?] ")[ ")
(modify-syntax-entry ?{ "(} ")
(modify-syntax-entry ?} "){ ")
(modify-syntax-entry ?\| " 23")
;; Other atom delimiters
(modify-syntax-entry ?\( "() ")
(modify-syntax-entry ?\) ")( ")
(modify-syntax-entry ?\; "< ")
(modify-syntax-entry ?\" "\" ")
(modify-syntax-entry ?' " p")
(modify-syntax-entry ?` " p")
;; Special characters
(modify-syntax-entry ?, "_ p")
(modify-syntax-entry ?@ "_ p")
(modify-syntax-entry ?# "_ p14")
(modify-syntax-entry ?\\ "\\ ")))
(defvar scheme-mode-abbrev-table nil "")
(define-abbrev-table 'scheme-mode-abbrev-table ())
(defun scheme-mode-variables ()
(set-syntax-table scheme-mode-syntax-table)
(setq local-abbrev-table scheme-mode-abbrev-table)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "$\\|" page-delimiter))
(make-local-variable 'paragraph-separate)
(setq paragraph-separate paragraph-start)
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'indent-line-function)
(setq indent-line-function 'scheme-indent-line)
(make-local-variable 'parse-sexp-ignore-comments)
(setq parse-sexp-ignore-comments t)
(make-local-variable 'comment-start)
(setq comment-start ";")
(make-local-variable 'comment-start-skip)
;; Look within the line for a ; following an even number of backslashes
;; after either a non-backslash or the line beginning.
(setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*")
(make-local-variable 'comment-column)
(setq comment-column 40)
(make-local-variable 'comment-indent-function)
(setq comment-indent-function 'scheme-comment-indent)
(make-local-variable 'parse-sexp-ignore-comments)
(setq parse-sexp-ignore-comments t)
(setq mode-line-process '("" scheme-mode-line-process)))
(defvar scheme-mode-line-process "")
(defun scheme-mode-commands (map)
(define-key map "\t" 'scheme-indent-line)
(define-key map "\177" 'backward-delete-char-untabify)
(define-key map "\e\C-q" 'scheme-indent-sexp))
(defvar scheme-mode-map nil)
(if (not scheme-mode-map)
(progn
(setq scheme-mode-map (make-sparse-keymap))
(scheme-mode-commands scheme-mode-map)))
;;;###autoload
(defun scheme-mode ()
"Major mode for editing Scheme code.
Editing commands are similar to those of lisp-mode.
In addition, if an inferior Scheme process is running, some additional
commands will be defined, for evaluating expressions and controlling
the interpreter, and the state of the process will be displayed in the
modeline of all Scheme buffers. The names of commands that interact
with the Scheme process start with \"xscheme-\". For more information
see the documentation for xscheme-interaction-mode.
Commands:
Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs. Semicolons start comments.
\\{scheme-mode-map}
Entry to this mode calls the value of scheme-mode-hook
if that value is non-nil."
(interactive)
(kill-all-local-variables)
(scheme-mode-initialize)
(scheme-mode-variables)
(run-hooks 'scheme-mode-hook))
(defun scheme-mode-initialize ()
(use-local-map scheme-mode-map)
(setq major-mode 'scheme-mode)
(setq mode-name "Scheme"))
(defvar scheme-mit-dialect t
"If non-nil, scheme mode is specialized for MIT Scheme.
Set this to nil if you normally use another dialect.")
(defun scheme-comment-indent (&optional pos)
(save-excursion
(if pos (goto-char pos))
(cond ((looking-at ";;;") (current-column))
((looking-at ";;")
(let ((tem (calculate-scheme-indent)))
(if (listp tem) (car tem) tem)))
(t
(skip-chars-backward " \t")
(max (if (bolp) 0 (1+ (current-column)))
comment-column)))))
(defvar scheme-indent-offset nil "")
(defvar scheme-indent-function 'scheme-indent-function "")
(defun scheme-indent-line (&optional whole-exp)
"Indent current line as Scheme code.
With argument, indent any additional lines of the same expression
rigidly along with this one."
(interactive "P")
(let ((indent (calculate-scheme-indent)) shift-amt beg end
(pos (- (point-max) (point))))
(beginning-of-line)
(setq beg (point))
(skip-chars-forward " \t")
(if (looking-at "[ \t]*;;;")
;; Don't alter indentation of a ;;; comment line.
nil
(if (listp indent) (setq indent (car indent)))
(setq shift-amt (- indent (current-column)))
(if (zerop shift-amt)
nil
(delete-region beg (point))
(indent-to indent))
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
;; If desired, shift remaining lines of expression the same amount.
(and whole-exp (not (zerop shift-amt))
(save-excursion
(goto-char beg)
(forward-sexp 1)
(setq end (point))
(goto-char beg)
(forward-line 1)
(setq beg (point))
(> end beg))
(indent-code-rigidly beg end shift-amt)))))
(defun calculate-scheme-indent (&optional parse-start)
"Return appropriate indentation for current line as scheme code.
In usual case returns an integer: the column to indent to.
Can instead return a list, whose car is the column to indent to.
This means that following lines at the same level of indentation
should not necessarily be indented the same way.
The second element of the list is the buffer position
of the start of the containing expression."
(save-excursion
(beginning-of-line)
(let ((indent-point (point)) state paren-depth desired-indent (retry t)
last-sexp containing-se